package com.ruoyi.web.controller.upload;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.dto.FileChunkDTO;
import com.ruoyi.system.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : weixu
 * @date : 2024/7/12 14:08
 */
@RestController
@RequestMapping("/simpleUpload")
public class UploadController extends BaseController {
    @Autowired
    private UploadService uploadService;

    /**
     * 检查分片
     *
     * @param chunkDTO
     * @return
     */
    @GetMapping("/chunk")
    public AjaxResult checkChunkExist(FileChunkDTO chunkDTO) {
        return AjaxResult.success(uploadService.checkChunkExist(chunkDTO));
    }

    /**
     * 分片上传
     * @param chunkDTO
     * @return
     */
    @PostMapping("/chunk")
    public AjaxResult uploadChunk(FileChunkDTO chunkDTO) {
        uploadService.uploadChunk(chunkDTO);
        return AjaxResult.success();
    }

    /**
     * 合并分片
     * @param md5
     * @return
     */
    @PostMapping("/merge")
    public AjaxResult merge(String md5) {
        return toAjax(uploadService.merge(md5));
    }

}
